﻿using System;
using System.Runtime.InteropServices;

namespace MyApp
{
    public static class Program
    {

        public delegate void RustMessageDelegate(string msg);


        [DllImport("protocol.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void startServer();



        [DllImport("protocol.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void init_callback(MessageCallback callback);

        public delegate void MessageCallback(string msg);


        private static void ReceiveMessageFrom(string msg)
        {
            Console.WriteLine("Received message : " + msg);
        }


        // 初始化回调函数
        public static void initializeCallback()
        {
            init_callback(ReceiveMessageFrom);
        }





        static void Main(string[] args)
        {
            initializeCallback();
            Thread thread = new Thread(executeDLL);
            // 启动线程
            thread.Start();
            Console.WriteLine("Main thread continues...");
            thread.Join();
        }



        static void executeDLL()
        {
            startServer();
        }
    }
}
